<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>用户信息表</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        .search-container {
            display: flex;
            align-items: center;
            padding: 10px;
        }

        .search-container input {
            padding: 10px;
            font-size: 16px;
            border-radius: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            width: 300px;
            transition: box-shadow 0.3s ease;
            margin-right: 10px;
        }

        .search-container input:focus {
            outline: none;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .search-container button {
            margin-right: 10px;
            background-color: #5FB878;
            color: #fff;
            border: none;
            border-radius: 20px;
            padding: 10px 20px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .search-container button:hover {
            background-color: #4cae4c;
        }
    </style>
</head>

<body>
<div class="layui-container">
    <div style="text-align: center;margin-bottom: 15px">
        <p1 style="font-size:28px;">用户信息表</p1>
    </div>
    <div class="search-container">
        <input type="text" id="searchOne" name="searchOne" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        <button type="button" class="layui-btn layui-btn-sm" onclick="searchUser()">查询</button>
    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th style="text-align: center">用户ID</th>
            <th style="text-align: center">用户姓名</th>
            <th style="text-align: center">用户密码</th>
            <th style="text-align: center">用户邮箱</th>
            <th style="text-align: center">用户电话</th>
            <th style="text-align: center">用户角色</th>
        </tr>
        </thead>
        <tbody id="tableBody">
        </tbody>
    </table>
</div>

<script src="../layui/layui.js"></script>
<script src="../js/public.js"></script>
<script>
    layui.use(['form', 'layer', 'table'], function () {
        var table = layui.table
            , form = layui.form, $ = layui.$;
        var geturl = url + user.allUserMsg;
        var element = layui.element;
        var $ = layui.jquery;

        $.ajax({
            type: "POST",
            url: geturl,
            data: JSON,
            contentType: 'application/json',
            success: function (data) {
                console.log(data)
                var tableBody = $('#tableBody');
                data.data.forEach(function (item) {
                    var row = '<tr>' +
                        '<td>' + item.userID + '</td>' +
                        '<td>' + item.username + '</td>' +
                        '<td>' + item.password + '</td>' +
                        '<td>' + item.email + '</td>' +
                        '<td>' + item.phoneNumber + '</td>' +
                        '<td>' + item.roleId + '</td>' +
                        '</tr>';
                    tableBody.append(row);
                });
            }
        });
    });

    function searchUser() {
        var geturl = url + user.searchUser;
        var element = layui.element;
        var $ = layui.jquery;
        var username = $('#searchOne').val();
        if (username) {
            $.ajax({
                type: "POST",
                url: geturl,
                data: JSON.stringify({ username: username }),
                contentType: 'application/json',
                success: function (data) {
                    console.log(data)
                    var tableBody = $('#tableBody');
                    tableBody.empty(); // 清空表格
                    var row = '<tr>' +
                        '<td>' + data.userID + '</td>' +
                        '<td>' + data.username + '</td>' +
                        '<td>' + data.password + '</td>' +
                        '<td>' + data.email + '</td>' +
                        '<td>' + data.phoneNumber + '</td>' +
                        '<td>' + data.roleId + '</td>' +
                        '</tr>';
                    tableBody.append(row);
                }
            })
        } else {
            layui.layer.msg('请输入用户名');
        }
    }
</script>
</body>

</html>
